package com.keon.jianbao.adapter;

import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.keon.jianbao.R;
import com.keon.jianbao.base.SimpleAdapter;
import com.keon.jianbao.bean.BeanActivity;
import com.keon.jianbao.util.UILUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by keon on 2015/9/2.
 */
public class HomeActivityAdapter extends SimpleAdapter {

    public HomeActivityAdapter(ArrayList data) {
        initData(data);
    }

    static class ViewHolder {
        @Bind(R.id.home_activity_title)
        TextView tvTitle;
        @Bind(R.id.home_activity_distance)
        TextView tvDistance;
        @Bind(R.id.home_activity_info)
        TextView tvInfo;
        @Bind(R.id.home_activity_img)
        ImageView ivImg;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    @Override
    protected View getRealView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if (convertView == null || convertView.getTag() == null) {
            convertView = getLayoutInflater(parent.getContext()).inflate(
                    R.layout.list_cell_home_activity, null);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }

        BeanActivity activity = (BeanActivity) mDatas.get(position);

        vh.tvTitle.setText(activity.getActivity_name());
        ImageLoader.getInstance().displayImage(activity.getActivity_image(), vh.ivImg, UILUtils.getOptions2());
        vh.tvInfo.setText(Html.fromHtml(activity.getActivity_intro()));

        vh.tvDistance.setText(activity.getCreate_time());

        return convertView;
    }
}
